<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/homePage' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>系统管理</el-breadcrumb-item>
                <el-breadcrumb-item>日志管理</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="queryLoginfoData"  class="demo-form-inline">
                <el-form-item >
                    <el-input v-model="queryLoginfoData.title" placeholder="请输入模块标题"></el-input>
                </el-form-item>
                <el-form-item >
                    <el-input v-model="queryLoginfoData.operName" placeholder="请输入操作人员"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="showAllLoginfo()">查询</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="logid"
                            label="日志id">
                    </el-table-column>
                    <el-table-column
                            prop="title"
                            label="模块标题">
                    </el-table-column>
                    <el-table-column
                            prop="businessType"
                            label="业务类型">
                        <template slot-scope="scope">
                            <span v-if="scope.row.businessType==0">查询</span>
                            <span v-if="scope.row.businessType==1">新增</span>
                            <span v-if="scope.row.businessType==2">修改</span>
                            <span v-if="scope.row.businessType==3">删除</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="method"
                            label="请求的方法名称">
                    </el-table-column>
                    <el-table-column
                            prop="operatorType"
                            label="操作类别">
                        <template slot-scope="scope">
                            <span v-if="scope.row.operatorType==1">后台用户</span>
                            <span v-if="scope.row.operatorType==2">手机端用户</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="operName"
                            label="操作人员">
                    </el-table-column>
                    <el-table-column
                            prop="operUrl"
                            label="请求路径">
                    </el-table-column>
                    <el-table-column
                            prop="ipaddr"
                            label="ip地址">
                    </el-table-column>
                    <el-table-column
                            prop="operLocation"
                            label="操作地点">
                    </el-table-column>
                    <el-table-column
                            prop="operParam"
                            label="请求参数" height="50">
                    </el-table-column>
                    <el-table-column
                            prop="status"
                            label="操作状态">
                        <template slot-scope="scope">
                            <span v-if="scope.row.status==0">正常</span>
                            <span v-if="scope.row.status==1">异常</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="errorMsg"
                            label="错误信息">
                    </el-table-column>
                    <el-table-column
                            prop="operTime"
                            label="操作时间">
                    </el-table-column>
                    <el-table-column label="操作" width="80">
                        <template slot-scope="scope">
                            <!-- 删除 -->
                            <el-button type="danger" icon="el-icon-delete" circle @click="deleteLoginfoById(scope.row.logid)"></el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: "",
        data() {
            return {
                queryLoginfoData: {
                    title: '',
                    operName: '',
                },
                tableData: [],
                pageSize: 5,
                currentPage: 1,
                total: 0,
            }
        },
        methods: {
            handleSizeChange(value) {
                this.pageSize = value;
                this.showAllLoginfo();
            },
            handleCurrentChange(value) {
                this.currentPage = value;
                this.showAllLoginfo();
            },
            // 查询全部的日志
            showAllLoginfo() {
                this.$axios({
                    method: 'get',
                    url: 'clms-system/loginfo/showAllLoginfo',
                    params: {
                        pageno: this.currentPage,
                        pagesize: this.pageSize,
                        title: this.queryLoginfoData.title,
                        operName: this.queryLoginfoData.operName
                    }
                }).then( result => {
                    this.tableData = result.data.listData;
                    this.total = result.data.object.total
                })
            },
            // 删除日志
            deleteLoginfoById(logid) {
                this.$axios({
                    method: 'get',
                    url: 'clms-system/loginfo/deleteLoginfoById',
                    params: {
                        logid: logid
                    }
                }).then( result => {
                    if (result.data.code == 200) {
                        this.$message.success(result.data.message);
                        this.showAllLoginfo()
                    } else {
                        this.$message.error(result.data.message);
                    }
                })
            }
        },
        created() {
            this.showAllLoginfo()
        }
    }
</script>
